package com.zhuangjie.order.mq.producer.config;

import com.zhuangjie.order.constant.OrderConstant;
import com.zhuangjie.order.mq.producer.event.OrderEvent;
import com.zhuangjie.order.mq.producer.structure.OrderMQStructure;
import com.zhuangjie.rabbit.config.wrap.ExchangeWrap;
import com.zhuangjie.rabbit.config.wrap.MQStructureConfig;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class OrderMQStructureConfig implements MQStructureConfig {

    @Override
    public List<ExchangeWrap> exchangeWrap() {
        ExchangeWrap exchangeWrap = new ExchangeWrap(ExchangeBuilder.topicExchange(OrderMQStructure.EXCHANGE_NAME).durable(true).build())
                .to(OrderEvent.ORDER_CANCEL, QueueBuilder.durable(OrderMQStructure.Queues.ORDER_CANCEL_QUEUE).build(), TimeUnit.MINUTES.toMillis(OrderConstant.PAYMENT_TIMEOUT) )
                .to(OrderEvent.ORDER_REFUND, QueueBuilder.durable(OrderMQStructure.Queues.ORDER_REFUND_QUEUE).build());
        return Arrays.asList(exchangeWrap);
    }

}
